/*
 ------------------------------------------------------------------------------
 Copyright (C) 2006-2007 Team Blur.

 This file is part of the Quantum Engine source code.

 The Quantum Engine source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quantum Engine source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quantum Engine source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


#ifndef __FRAMEWORK_CMDSYSTEM_H__
#define __FRAMEWORK_CMDSYSTEM_H__


typedef void				(*cmdFunction_t)(void);

typedef enum {
	CMD_EXEC_APPEND,							// Append at the end of the command buffer
	CMD_EXEC_INSERT,							// Insert at the beginning of the command buffer
	CMD_EXEC_NOW								// Don't return until completed
} cmdExec_t;

/*
 ==============================================================================

 FUNCTIONS EXPORTED BY THE ENGINE

 ==============================================================================
*/

typedef struct {
	// Adds a command and the function to call for it.
	// If function is NULL, the command will be forwarded to the server instead
	// of executed locally.
	// The description parameter can be NULL if you don't want it.
	void					(*AddCommand)(const char *name, cmdFunction_t function, const char *description);

	// Removes a command
	void					(*RemoveCommand)(const char *name);

	// Returns the number of arguments
	int						(*Argc)(void);

	// Returns the given argument.
	// Will return an empty string, not NULL, if arg < 0 or arg >= argc, so
	// string operations are always safe.
	const char *			(*Argv)(int arg);

	// Returns a string containing argv[start] to argv[end]. Specifying 1 for
	// start and -1 for end will return all the arguments. Specifying 0 for
	// start will also include the command.
	// If tokenized is false, the original, unmodified command string will be
	// returned (ignoring the end parameter).
	const char *			(*Args)(int start, int end, bool tokenized);

	// Parses the given string into command line tokens. Does not need to be \n
	// terminated.
	// The text is copied to a separate buffer and 0 characters are inserted in
	// the appropriate place. The argv array will point into this temporary
	// buffer.
	// $CVars will be expanded unless they are in a quoted string.
	void					(*TokenizeString)(const char *text);

	// This can be used in place of either Cmd_AppendText or Cmd_InsertText
	void					(*ExecuteText)(cmdExec_t exec, const char *text);
} odCmdSystem_t;


#endif	// __FRAMEWORK_CMDSYSTEM_H__
